/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JP_Permisos_Buscar.java
 *
 * Created on 14-jun-2014, 18:37:53
 */

package pck_gui;

import java.util.ArrayList;
import javax.swing.table.DefaultTableModel;
import pck_pojos.Cls_Profesion;
import pck_pojos.Cls_TipoPermiso;
import pck_utilitarios.Cls_Funciones;
import pck_utilitarios.Cls_InvocaWebService;
import pck_utilitarios.Cls_Parametros;
import pck_utilitarios.JP_Modelo;

/**
 *
 * @author AngelAndres
 */
public class JP_Permisos_Buscar extends  JP_Modelo {

    /** Creates new form JP_Permisos_Buscar */
    public JP_Permisos_Buscar() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLayeredPane1 = new javax.swing.JLayeredPane();
        jLabel1 = new javax.swing.JLabel();
        TXT_FILTRO = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        TBL_PERMISOS_BUSCAR = new javax.swing.JTable();

        jLayeredPane1.setBorder(javax.swing.BorderFactory.createTitledBorder("Mantenimiento de Permisos "));
        jLayeredPane1.setName("jLayeredPane1"); // NOI18N

        jLabel1.setText("Permiso");
        jLabel1.setName("jLabel1"); // NOI18N
        jLabel1.setBounds(30, 30, 60, 14);
        jLayeredPane1.add(jLabel1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        TXT_FILTRO.setName("TXT_FILTRO"); // NOI18N
        TXT_FILTRO.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                TXT_FILTROKeyPressed(evt);
            }
        });
        TXT_FILTRO.setBounds(90, 30, 160, 20);
        jLayeredPane1.add(TXT_FILTRO, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jButton1.setText("Buscar");
        jButton1.setName("jButton1"); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jButton1.setBounds(270, 30, 65, 23);
        jLayeredPane1.add(jButton1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        TBL_PERMISOS_BUSCAR.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Codigo", "Descripcion"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        TBL_PERMISOS_BUSCAR.setName("TBL_PERMISOS_BUSCAR"); // NOI18N
        TBL_PERMISOS_BUSCAR.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                TBL_PERMISOS_BUSCARMouseClicked(evt);
            }
        });
        TBL_PERMISOS_BUSCAR.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                TBL_PERMISOS_BUSCARKeyPressed(evt);
            }
        });
        jScrollPane1.setViewportView(TBL_PERMISOS_BUSCAR);

        jScrollPane1.setBounds(20, 80, 320, 150);
        jLayeredPane1.add(jScrollPane1, javax.swing.JLayeredPane.DEFAULT_LAYER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 361, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLayeredPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
                String fila[];
        DefaultTableModel mode = (DefaultTableModel) this.TBL_PERMISOS_BUSCAR.getModel();
        String filtro;
       if(TXT_FILTRO.getText().length()==0){
               filtro="dsgsdfgfdgsgagsgfdsdsfdgsdgdgdsg";
       }else{
            filtro=TXT_FILTRO.getText();
        }
        String parametrosParaService_01[] = {Cls_Parametros.Map_FILTRO_NOMBRE,filtro };
        ArrayList<Cls_TipoPermiso> array_permisos = Cls_InvocaWebService.obtenerTodosPermisos(Cls_Funciones.generarHashMapParaSolicitud(parametrosParaService_01));
        while (mode.getRowCount() > 0) {

            mode.removeRow(0);
        }
            for (Cls_TipoPermiso permisos : array_permisos) {
            fila = new String[2];
            fila[0] = permisos.getId();
            fila[1] = permisos.getDescripcion();
            mode.addRow(fila);
        }
       // this.TBL_PERMISOS_BUSCAR.setModel(mode);
        this.TBL_PERMISOS_BUSCAR.requestFocus();
    }//GEN-LAST:event_jButton1ActionPerformed
    
    private void TBL_PERMISOS_BUSCARMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_TBL_PERMISOS_BUSCARMouseClicked
        if (evt.getClickCount() == 2) {
            seleccionarFila();
        }
    }//GEN-LAST:event_TBL_PERMISOS_BUSCARMouseClicked

    private void TBL_PERMISOS_BUSCARKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TBL_PERMISOS_BUSCARKeyPressed
       if (evt.getKeyCode() == 10) { // tecla enter
            seleccionarFila();
        }
    }//GEN-LAST:event_TBL_PERMISOS_BUSCARKeyPressed

    private void TXT_FILTROKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_TXT_FILTROKeyPressed
        if (evt.getKeyCode() == 10) { // tecla enter
           jButton1.requestFocus();
        }
    }//GEN-LAST:event_TXT_FILTROKeyPressed

 private void seleccionarFila() {
        try {

            String codigo = "", descripcion = "";
            codigo = (String) this.TBL_PERMISOS_BUSCAR.getValueAt(this.TBL_PERMISOS_BUSCAR.getSelectedRow(), 0);
            descripcion = (String) this.TBL_PERMISOS_BUSCAR.getValueAt(this.TBL_PERMISOS_BUSCAR.getSelectedRow(), 1);
            Cls_TipoPermiso obj_permiso = new Cls_TipoPermiso(codigo,descripcion);
          //  if (this.getRefDep() instanceof JP_Profesiones_Mantenimiento) {
                ((JP_Permisos_Mantenimiento) this.getRefDep()).obtenerPermiso(obj_permiso);
               
           /// }
            this.cerrarPadre();
        } catch (ArrayIndexOutOfBoundsException e) {
//            e.printStackTrace();
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTable TBL_PERMISOS_BUSCAR;
    private javax.swing.JTextField TXT_FILTRO;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLayeredPane jLayeredPane1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

}
